﻿package plugin.npcDialog.ui.panels.hctwo
{
    import cmd.*;
    import com.core.*;
    import flash.events.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.npcdialogs.*;

    public class RxhcPL extends RxhcUI implements INpcDialogContent
    {
        private var newshcgonfig:Object;
        private var itemconfig:Object;
        private var erjiArr:Array;
        private var rx_int:int;
        private var user_sex:int;
        private var userid:int;
        private var bag_ct:int;
        private var pz_count:int;
        private var xuyao_name:String;
        private var hec_name:String;

        public function RxhcPL()
        {
            this.newshcgonfig = ConfigDictionary.data.newsrl;
            this.itemconfig = ConfigDictionary.data.item;
            this.erjiArr = [];
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            var _loc_7:String = null;
            var _loc_8:Object = null;
            var _loc_9:int = 0;
            var _loc_11:Object = null;
            hcLVbox.visible = true;
            this.userid = UserData.getUserData("career");
            var _loc_3:* = UserData.getUserData();
            this.user_sex = _loc_3.sex;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            fanhuiLink.addEventListener(MouseEvent.CLICK, this.Onfanhui);
            shuomingLink.addEventListener(MouseEvent.MOUSE_OVER, this.OnSmtip);
            var _loc_4:Array = [];
            var _loc_5:Array = [];
            var _loc_6:Array = [];
            txt_desc.text = "可将热血碎片合成热血套装";
            txt_desc.align = "left";
            if (this.userid == 1)
            {
                _loc_7 = "战士";
            }
            else if (this.userid == 2)
            {
                _loc_7 = "法师";
            }
            else
            {
                _loc_7 = "道士";
            }
            title_hec.text = _loc_7 + "套装合成";
            for each (_loc_8 in this.newshcgonfig)
            {
                
                if (_loc_8.littletype)
                {
                    _loc_6.push(_loc_8.littletype);
                }
            }
            _loc_5 = this.filterArray(_loc_6);
            _loc_5.sort(Array.NUMERIC);
            _loc_9 = 0;
            while (_loc_9 < _loc_5.length)
            {
                
                for each (_loc_11 in this.newshcgonfig)
                {
                    
                    if (_loc_11.littletype == _loc_5[_loc_9])
                    {
                        _loc_4.push(_loc_11);
                        break;
                    }
                }
                _loc_9++;
            }
            var _loc_10:int = 0;
            while (_loc_10 < _loc_4.length)
            {
                
                if (_loc_4[_loc_10].id != _loc_4[_loc_10].littletype)
                {
                    this["rxtaozhuanBT" + _loc_10].labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    this["rxtaozhuanBT" + _loc_10].addEventListener(MouseEvent.CLICK, this.OnClick60);
                    this["rxtaozhuanBT" + _loc_10].name = _loc_10 + 1;
                }
                else
                {
                    this["rxtaozhuanBT" + _loc_10].labelColors = "0x73716B";
                    this["rxtaozhuanBT" + _loc_10].addEventListener(MouseEvent.MOUSE_OVER, this.OnClicktips);
                }
                _loc_10++;
            }
            return;
        }// end function

        protected function OnClicktips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color = \'#997f60\'>尚未开放</font>");
            event.target.addEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        protected function closeTips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            event.target.removeEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        protected function OnClick60(event:MouseEvent) : void
        {
            erjibox.visible = true;
            hcLVbox.visible = false;
            shuomingLink.visible = true;
            fanhuiLink.visible = true;
            this.rx_int = int(event.currentTarget.name);
            this.showlist(this.rx_int);
            return;
        }// end function

        private function showlist(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            if (this.userid == 1)
            {
                _loc_2 = "战士";
            }
            else if (this.userid == 2)
            {
                _loc_2 = "法师";
            }
            else
            {
                _loc_2 = "道士";
            }
            this.erjiArr = [];
            titleLb.text = _loc_2 + "热血套装合成";
            for each (_loc_3 in this.newshcgonfig)
            {
                
                if (_loc_3.littletype == param1)
                {
                    if (_loc_3.career == this.userid && _loc_3.sex == 2 || _loc_3.career == this.userid && _loc_3.sex == this.user_sex)
                    {
                        _loc_4 = {};
                        _loc_4.cfg = this.itemconfig[_loc_3.id];
                        this.hec_name = this.itemconfig[_loc_3.id].name;
                        this.xuyao_name = this.itemconfig[_loc_3.needitem].name;
                        this.erjiArr.push([_loc_4.cfg, this.hec_name, this.xuyao_name, _loc_3.needitem]);
                        this.pz_count = _loc_3.count;
                    }
                }
            }
            _list.array = this.erjiArr;
            _list.renderHandler = new Handler(this.ComlistRander);
            return;
        }// end function

        private function ComlistRander(param1:Component, param2:int) : void
        {
            var _loc_3:Label = null;
            var _loc_4:LinkButton = null;
            var _loc_5:LinkButton = null;
            var _loc_6:int = 0;
            if (param2 < _list.array.length)
            {
                _loc_3 = param1.getChildByName("xuyaoLabel") as Label;
                _loc_4 = param1.getChildByName("lvname") as LinkButton;
                _loc_4.label = _list.array[param2][1];
                _loc_3.text = _list.array[param2][2] + " X" + this.pz_count + "=";
                _loc_4.removeEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_4.addEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_5 = param1.getChildByName("hcname") as LinkButton;
                _loc_5.addEventListener(MouseEvent.CLICK, this.OnClickbtn);
                _loc_6 = this.getallcount(_list.array[param2][3]);
                if (_loc_6 < this.pz_count)
                {
                    _loc_5.labelColors = "0x73716B";
                    _loc_3.color = "0x73716B";
                    _loc_4.labelColors = "0x73716B";
                }
                else
                {
                    _loc_5.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_3.color = "0x53b436";
                    _loc_4.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                }
            }
            return;
        }// end function

        protected function OnOverlvtips(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource;
            _loc_2[0].wear = 0;
            ModelProxy.change("tips", "arm", {data:_loc_2, p:new Point(event.stageX, event.stageY)});
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            return;
        }// end function

        protected function OnCloselvtips(event:MouseEvent) : void
        {
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function OnClickbtn(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource[0].itemid;
            PluginManager.instance.sendToServer("qianghua", CMDQiangHua.DoCompound2, _loc_2);
            return;
        }// end function

        protected function Onfanhui(event:MouseEvent) : void
        {
            hcLVbox.visible = true;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            return;
        }// end function

        protected function OnSmtip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color = \'#997f60\'>击杀转生神殿和和幻境中的boss可获得热血碎片</font>");
            shuomingLink.addEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        protected function OnSmclosetip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            shuomingLink.removeEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            this.showlist(this.rx_int);
            return;
        }// end function

        public function getallcount(param1:int) : int
        {
            var _loc_6:Object = null;
            var _loc_2:int = 0;
            var _loc_3:* = UserData.getBagData();
            var _loc_4:* = _loc_3.maxcount;
            var _loc_5:int = 1;
            while (_loc_5 < _loc_4)
            {
                
                _loc_6 = _loc_3[_loc_5];
                if (_loc_6)
                {
                    if (_loc_6[4] && int(_loc_6[4].itemid) == param1)
                    {
                        _loc_2 = _loc_2 + _loc_6[1];
                    }
                }
                _loc_5++;
            }
            return _loc_2;
        }// end function

        private function filterArray(param1:Array) : Array
        {
            var _loc_2:Array = [];
            var _loc_3:* = param1.length;
            var _loc_4:uint = 0;
            while (_loc_4 < _loc_3)
            {
                
                if (_loc_2.indexOf(param1[_loc_4]) == -1)
                {
                    _loc_2.push(param1[_loc_4]);
                }
                _loc_4 = _loc_4 + 1;
            }
            return _loc_2;
        }// end function

    }
}
